﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyThuVien.DAL
{
    class daoMuonTra
    {
        Connection connect = new Connection();

        public bool SuaMuonTra(String MaDocGia, String MaSach, DateTime NgayGiaHanTra)
        {
            SqlParameter[] Parameters = new SqlParameter[3];
            Parameters[0] = new SqlParameter("@MaDocGia", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaDocGia;
            Parameters[1] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[1].Value = MaSach;
            Parameters[2] = new SqlParameter("@NgayGiaHanTra", SqlDbType.Date);
            Parameters[2].Value = NgayGiaHanTra;
            return connect.executeUpdateProcedureQuery("SuaMuonTra", Parameters);
        }

        public bool XoaMuonTra(String MaDocGia, String MaSach)
        {
            SqlParameter[] Parameters = new SqlParameter[2];
            Parameters[0] = new SqlParameter("@MaDocGia", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaDocGia;
            Parameters[1] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[1].Value = MaSach;
            return connect.executeDeleteProcedureQuery("XoaMuonTra", Parameters);
        }

        public bool ThemMuonTra(String MaDocGia, String MaSach, DateTime NgayGiaHanTra)
        {
            SqlParameter[] Parameters = new SqlParameter[3];
            Parameters[0] = new SqlParameter("@MaDocGia", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaDocGia;
            Parameters[1] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[1].Value = MaSach;
            Parameters[2] = new SqlParameter("@NgayGiaHanTra", SqlDbType.Date);
            Parameters[2].Value = NgayGiaHanTra;
            return connect.executeInsertProcedureQuery("ThemMuonTra", Parameters);
        }

        public DataTable TimMuonTra(String MaSach, String TenSach, String TacGia, String NhaXuatBan,
                            String MaDocGia, String TenDocGia, DateTime NgayMuonMin, DateTime NgayMuonMax)
        {
            SqlParameter[] Parameters = new SqlParameter[8];
            Parameters[0] = new SqlParameter("@MaSach", SqlDbType.VarChar, 10);
            Parameters[0].Value = MaSach;
            Parameters[1] = new SqlParameter("@TenSach", SqlDbType.NVarChar, 50);
            Parameters[1].Value = TenSach;
            Parameters[2] = new SqlParameter("@TacGia", SqlDbType.NVarChar, 50);
            Parameters[2].Value = TacGia;
            Parameters[3] = new SqlParameter("@NhaXuatBan", SqlDbType.NVarChar, 50);
            Parameters[3].Value = NhaXuatBan;
            Parameters[4] = new SqlParameter("@MaDocGia", SqlDbType.VarChar, 10);
            Parameters[4].Value = MaDocGia;
            Parameters[5] = new SqlParameter("@TenDocGia", SqlDbType.NVarChar, 50);
            Parameters[5].Value = TenDocGia;
            Parameters[6] = new SqlParameter("@NgayMuonMin", SqlDbType.Date);
            Parameters[6].Value = NgayMuonMin;
            Parameters[7] = new SqlParameter("@NgayMuonMax", SqlDbType.Date);
            Parameters[7].Value = NgayMuonMax;
            return connect.executeSelectProcedureQuery("TimMuonTra", Parameters);
        }
    }
}
